import Vue from 'vue'
import App from './App.vue'
import router from './router'

Vue.config.productionTip = false;
import 'ant-design-vue/dist/antd.css';
import {  Modal,Form,Input,Button,Checkbox,      Layout,
  Menu,
  Icon,
  Select,
  Table,
Tag,
Divider, } from 'ant-design-vue';

Vue.use(Modal);
Vue.use(Form);
Vue.use(Input);
Vue.use(Button);
Vue.use(Checkbox);
Vue.use(Layout);
Vue.use(Menu);
Vue.use(Icon);
Vue.use(Select);
Vue.use(Table);
Vue.use(Tag);
Vue.use(Divider);


router.beforeEach((_to,_from,next) =>{
  const token = localStorage.getItem("login_token");
  if(token){
    next()
  }else{
    const {href,origin,pathname} = location;
    const writeRouters=['/login','/register'];
    if(writeRouters.includes(pathname)){
      next()
    }else{
      location.href = `${origin}/login?callback=${href.replace(origin,"")}`;
    }
  }
})


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
